import React, { useContext } from 'react';
import { ConfigProvider, Checkbox as AntdCheckbox } from 'antd';
import type { CheckboxProps as AntdCheckboxProps } from 'antd';

import { useCheckboxStyles } from './style';
import { checkboxThemeConfig } from '../../themes/checkbox';

// 导出样式扩展 Hook，方便用户使用特殊效果
export { useCheckboxStyles } from './style';

export interface CheckboxProps extends AntdCheckboxProps {
  // 继承所有 antd Checkbox 属性，无需额外属性
}

const CheckboxComponent: React.FC<CheckboxProps> = ({ 
  className,
  ...restProps 
}) => {
  const { styles, cx } = useCheckboxStyles();
  const context = useContext(ConfigProvider.ConfigContext);
  
  // 合并样式：基础样式 + 用户样式
  const checkboxClassName = cx(
    styles.enhancedCheckbox,      // 基础样式增强
    className                      // 用户自定义样式
  );

  return (
    <ConfigProvider
      theme={{
        components: {
          Checkbox: {
            ...checkboxThemeConfig,
            ...context?.theme?.components?.Checkbox,
          },
        },
      }}
    >
      <AntdCheckbox 
        className={checkboxClassName} 
        {...restProps} 
      />
    </ConfigProvider>
  );
};

const Checkbox = Object.assign(CheckboxComponent, {
  Group: AntdCheckbox.Group,
});

export { Checkbox };
export default Checkbox;
